import mvvmQt.attrTypes as t
import mvvmQt.attrFuncs as f

"""
结构格式为key: [qt function name or callable function, type]
如果为callable function, 最后一个参数必然为Element对象
"""

size = {
    'maxHeight': ['setMaximumHeight', int],
    'maxWidth': ['setMaximumWidth', int],
    'minHeight': ['setMinimumHeight', int],
    'minWidth': ['setMinimumWidth', int],
    'width': ['setFixedWidth', int],
    'height': ['setFixedHeight', int],
    'visible': ['setVisible', [int, bool]],
    'sizePolicy': ['setSizePolicy', t.sizePolicy],
    'autoSize': [f.autoSize, None]
}

common = {
    'text': ['setText', str],
    'enable': ['setEnabled', [int, bool]]
}

align = {
    'align': ['setAlignment', t.alignment]
}

btn = {
    'checked': ['setChecked', [int, bool]],
    'checkable': ['setCheckable', [int, bool]]
}

style = {
    'cursor': ['setCursor', t.cursorType],
    'qss': ['setStyleSheet', [str, t.readFile]],
    'style': [f.setStyleSheet, str],
    'objName': ['setObjectName', str]
}

spacing = {
    'spacing': ['setSpacing', int],
    'vspacing': ['setVerticalSpacing', int],
    'hspacing': ['setHorizontalSpacing', int]
}

spinbox = {
    **style, **size,
    'value': [f.valueChanged, None],
    'wrapping': ['setWrapping', bool],
    'prefix': ['setPrefix', str],
    'suffix': ['setSuffix', str]
}

ElementAttr = {
    'widget': {
        **size,
        **style,
        'title': ['setWindowTitle', str],
        'pos': ['move', t.toList(int)],
        'full': ['showType', [int, bool]]
    },
    'frame': {
        **size, **style,
        'shape': ['setFrameShape', t.frameShape],
        'shadow': ['setFrameShadow', t.frameShadow],
        'linew': ['setLineWidth', int],
        'lineMw': ['setMidLineWidth', int],
    },
    'grid': {
        **spacing,
        'columnWidth': ['setColumnMinimumWidth', t.toList(int)],
        'rowHeight': ['setRowMinimumHeight', t.toList(int)]
    },
    'vbox': {
        **spacing
    },
    'hbox': {
        **spacing
    },
    'button-group': {
        'exclusive': ['setExclusive', [int, bool]],
        'checked': [f.groupChecked, None]
    },
    'button': {
        **size, **common, **btn, **style,
        'shortcut': ['setShortcut', str],
        'tooltip': ['setToolTip', str],
        'icon': ['setIcon', str],
        'repeat': ['setAutoRepeat', [int, bool]],
        'repeatDelay': ['setAutoRepeatDelay', int],
        'repeatInterval': ['setAutoRepeatInterval', int]
    },
    'radio': {
        **size, **common, **btn, **style
    },
    'label': {
        **size, **common, **align, **style,
        'cv': ['setTextOrPixmap', t.cvImg],
        'cvPath': ['setPixmap', [str, t.cvPathImg]],
        'scaledContents': ['setScaledContents', [int, bool]]
    },
    'tab': {
        **style,
        'pos': ['setTabPosition', t.tabPosition],
        'name': ['setTabText', t.toList([int, str])]
    },
    'status': {
        **style,
        'msg': ['showMessage', str]
    },
    'select': {
        **style,
        'index': [f.indexChanged, None]
    },
    'text-edit': {
        **size,
        **style,
        'text': [f.textChanged, None],
        'html': [f.htmlChanged, None],
        'readonly': ['setReadOnly', [int, bool]]
    },
    'menu': {
        **style,
        'title': ['setTitle', str]
    },
    'action': {
        **style,
        'text': ['setText', str],
        'tooltip': ['setToolTip', str],
        'shortcut': ['setShortcut', str],
        'enable': ['setEnabled', [int, bool]],
        'checked': ['setChecked', [int, bool]],
        'checkable': ['setCheckable', [int, bool]]
    },
    'dial': {
        **style, **size,
        'min': ['setMinimum', int],
        'max': ['setMaximum', int],
        'notches': ['setNotchesVisible', [int, bool]],
        'pageStep': ['setPageStep', int],
        'wrapping': ['setWrapping', [int, bool]],
        'value': [f.valueChanged, None]
    },
    'slider': {
        **style, **size,
        'min': ['setMinimum', int],
        'max': ['setMaximum', int],
        'tick-pos': ['setTickPosition', t.sliderPos],
        'step': ['setSingleStep', int],
        'page-step': ['setPageStep', int],
        'interval': ['setTickInterval', int],
        'dir': ['setOrientation', t.dir],
        'enabled': ['setEnabled', [int, bool]],
        'value': [f.valueChanged, None]
    },
    'svg': {
        **style, **size,
        'load': ['load', str],
        'bload': ['load', t.toBytes]
    },
    'input': {
        **style, **size,
        'mask': ['setInputMask', str],
        'placeholder': ['setPlaceholderText', str],
        'echo': ['setEchoMode', t.echoMode],
        'enable': ['setEnabled', [int, bool]],
        'text': [f.textChanged, None]
    },
    'spin-box': {
        **spinbox,
        'range': ['setRange', t.toList([int, int])],
        'min': ['setMinimum', int],
        'max': ['setMaximum', int],
        'step': ['setSingleStep', int]
    },
    'double-spin-box': {
        **spinbox,
        'range': ['setRange', t.toList([float, float])],
        'min': ['setMinimum', float],
        'max': ['setMaximum', float],
        'step': ['setSingleStep', float],
        'decimal': ['setDecimals', float],
        'special-value-text': ['setSpecialValueText', str],
        'fixed': ['setFixed', int]
    },
    'lcd': {
        **size, **align, **style,
        'display': ['display', float],
        'text': ['display', str],
        'digit-count': ['setDigitCount', int],
        'mode': ['setMode', t.lcdMode],
        'show-decimal': ['setSmallDecimalPoint', [int, bool]],
        'segment': ['setSegmentStyle', t.lcdStyle]
    },
    'progress': {
        **size, **style, **align,
        'min': ['setMinimum', int],
        'max': ['setMaximum', int],
        'value': ['setValue', int],
        'format': ['setFormat', str],
        'dir': ['setOrientation', t.dir],
        'inverted': ['setInvertedAppearance', [int, bool]],
        'textDir': ['setTextDirection', t.progressTextDir]
    }
}

ElementAttr['window'] = {
    **ElementAttr['widget']
}